package cn.net.mysoft.account.cli.control;

import cn.net.mysoft.account.api.common.DateTimeTool;
import cn.net.mysoft.account.api.common.VnoProvider;
import cn.net.mysoft.account.api.constant.AccountConstant;
import cn.net.mysoft.account.api.protocol.RefundInfo;
import cn.net.mysoft.account.api.protocol.TransferInfo;
import cn.net.mysoft.account.api.service.AccountFeignService;
import cn.net.mysoft.account.api.service.AccountService;
import cn.net.mysoft.account.api.service.YcbAccountFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;
import java.util.TreeMap;

@RestController
public class Test {
    @Autowired
    YcbAccountFeignService objAccountService;

    @RequestMapping("/")
    Map<String,String> indexPage(){
        Map<String,String> res = new TreeMap<>();

        res.put("balance",String.valueOf(objAccountService.getBalance("A")));


        TransferInfo itm = new TransferInfo();
        itm.setType(1);
        itm.setVno(VnoProvider.getInstance().getUniqueString());
        itm.setAmt(1000);
        itm.setDesc("test");
        itm.setFrom(AccountConstant.CA_CHARGE);
        itm.setTo("A");

        RefundInfo rinfo = new RefundInfo();
        rinfo.setDesc("refund");
        rinfo.setRefundVno(VnoProvider.getInstance().getUniqueString());
        rinfo.setFrom(itm.getFrom());
        rinfo.setTo(itm.getTo());
        rinfo.setVno(itm.getVno());
        rinfo.setRefundAmt(1);

        res.put("transfer",String.valueOf(objAccountService.transfer(itm)));


        res.put("refund",String.valueOf(objAccountService.refund(rinfo)));

        res.put("reverse",String.valueOf(objAccountService.reverse(itm)));

        res.put("detail",String.valueOf(objAccountService.getAccountDetail("A",
                DateTimeTool.getBeforeDateTime(186400),
                DateTimeTool.getCurrentDateTime(),
                0,100
                ))
        );
        return res;
    }
}
